package kr.co.icebird.swt.app.ch4;

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

public class Ch4_Contributions extends ApplicationWindow {

	StatusLineManager slm = new StatusLineManager();
	Ch4_StatusAction statusAction = new Ch4_StatusAction(slm);
	ActionContributionItem aci = new ActionContributionItem(statusAction);

	public Ch4_Contributions() {
		super(null);
		addStatusLine();
		addMenuBar();
		addToolBar(SWT.FLAT | SWT.WRAP);
	}

	protected Control createContents(Composite parent) {
		getShell().setText("Action/Contribution Example");
		parent.setSize(290, 150);
		aci.fill(parent);
		return parent;
	}

	protected MenuManager createMenuManager() {
		MenuManager mainMenu = new MenuManager(null);
		MenuManager actionMenu = new MenuManager("Menu");

		mainMenu.add(actionMenu);
		actionMenu.add(statusAction);
		return mainMenu;
	}

	protected ToolBarManager createToolBarManager(int style) {
		ToolBarManager toolBarManager = new ToolBarManager(style);
		toolBarManager.add(statusAction);
		return toolBarManager;
	}

	protected StatusLineManager createStatusLineManager() {
		return slm;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Ch4_Contributions mwin = new Ch4_Contributions();
		mwin.setBlockOnOpen(true);
		mwin.open();
		Display.getCurrent().dispose();
	}

}
